package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketCollect;
import com.cskaoyan.market.db.domain.MarketCollectExample;
import com.cskaoyan.market.db.mapper.MarketCollectMapper;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: YaLiFeng
 * @description: TODO
 * @date: 2024/5/7 10:47
 */
@Service
public class MarketCollectServiceImpl implements MarketCollectService {
    @Autowired
   MarketCollectMapper marketCollectMapper;

    @Override
    public List<MarketCollect> list(Integer page, Integer limit, String sort, String order, String userId, String goodId) {
        MarketCollectExample marketCollectExample = new MarketCollectExample();
        marketCollectExample.setOrderByClause(sort + " " + order);
        MarketCollectExample.Criteria criteria = marketCollectExample.createCriteria();
        if (!StringUtils.isEmpty(userId)) {
            criteria.andUserIdEqualTo(Integer.valueOf(userId));
        }
        if (!StringUtils.isEmpty(goodId)) {
            criteria.andValueIdEqualTo(Integer.valueOf(goodId));
        }
        criteria.andLogicalDeleted(true);
        PageHelper.startPage(page, limit);
        List<MarketCollect> marketCollects = marketCollectMapper.selectByExampleSelective(marketCollectExample, MarketCollect.Column.id, MarketCollect.Column.userId,
                MarketCollect.Column.valueId, MarketCollect.Column.addTime, MarketCollect.Column.type, MarketCollect.Column.deleted);
        return marketCollects;
    }
}
